package com.nuorui.module.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.RoleForm;
import com.nuorui.module.system.domain.entity.RoleEntity;
import com.nuorui.module.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 角色管理
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2021-10-22 10:42
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_ROLE)
public class RoleController {

    private final RoleService roleService;

    @GetMapping("/roles")
    @ApiOperation(value = "列表查询", notes = "列表查询")
    public ResponseDTO list(RoleEntity role) {
        return ResponseDTO.ok(roleService.list(Wrappers.query(role)));
    }

    @PostMapping("/roles")
    @ApiOperation(value = "新增角色", notes = "新增角色")
    public ResponseDTO save(@Valid @RequestBody RoleForm roleDTO) {
        return roleService.saveRole(roleDTO);
    }

    @PutMapping("/roles/{roleId}")
    @ApiOperation(value = "变更角色", notes = "变更角色")
    public ResponseDTO update(@PathVariable("roleId") Long roleId, @Valid @RequestBody RoleForm roleDTO) {
        return roleService.updateRole(roleId, roleDTO);
    }

    @DeleteMapping("/roles/{roleId}")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    public ResponseDTO removeById(@PathVariable("roleId") Long roleId) {
        return roleService.removeRole(roleId);
    }
}
